package ModelLayer;
import java.util.ArrayList;



public class OrderList
{
    
    public ArrayList<Order> orders;
    private static OrderList instance;

    
    public OrderList()
    {
    orders = new ArrayList<Order>();    
    }

    public static OrderList getInstance()
    {
        if(instance == null)
        {
            instance = new OrderList();
        }
        return instance;
    }
    
    public void addOrder (Order newOrder)
    {
    orders.add(newOrder);
    }
    
    public void deleteOrder(long orderId)
    {
        Order order = findOrder(orderId);
        orders.remove(order);
    }
    
  
    public int size()
    {
    	return orders.size();
    }
    
    public Order findOrder(long orderId)
    {
        boolean orderFound = false;
        int index = 0;
        while(index < orders.size() && !orderFound)
        {
            Order s = orders.get(index);
            if(s.getOrderId() == orderId)
            {
                orderFound = true; 
            }
            else
            {
                index++;
            }
            
        }
        
        if(orderFound)
        {
            return orders.get(index);
        }
        else
        {
            
            return null;
        }
    }
    
    


}
